//
//  UIBarButtonItem+HJYitem.m
//  BuDeJie
//
//  Created by 胡大力 on 2016/12/6.
//  Copyright © 2016年 nebula. All rights reserved.
//

#import "UIBarButtonItem+HJYitem.h"

@implementation UIBarButtonItem (HJYitem)

//利用view封装button 解决超出响应范围的问题
+ (instancetype)barButtonitemWithImageName:(NSString *)name HightlightName:(NSString *)HightlightName target:(id)target action:(SEL)action {
    
    UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
    
    [btn setImage:[UIImage imageNamed:name] forState:UIControlStateNormal];
    [btn setImage:[UIImage imageNamed:HightlightName] forState:UIControlStateHighlighted];
    [btn sizeToFit];
    [btn addTarget:target action:action forControlEvents:UIControlEventTouchUpInside];
    
    //view包装button
    UIView *contentView = [[UIView alloc] initWithFrame: btn.bounds];
    [contentView addSubview: btn];
    
    return [[self alloc] initWithCustomView:contentView];
}

+ (instancetype)barButtonitemWithImageName:(NSString *)name selectedName:(NSString *)selectedName target:(id)target action:(SEL)action {
    
    UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
    
    [btn setImage:[UIImage imageNamed:name] forState:UIControlStateNormal];
    [btn setImage:[UIImage imageNamed:selectedName] forState:UIControlStateSelected];
    [btn sizeToFit];
    [btn addTarget:target action:action forControlEvents:UIControlEventTouchUpInside];
    
    //view包装button
    UIView *contentView = [[UIView alloc] initWithFrame:btn.bounds];
    [contentView addSubview:btn];
    
    return [[self alloc] initWithCustomView:contentView];
}

@end
